package com.yty.controller;

import com.yty.pojo.Emp;
import com.yty.pojo.LoginInfo;
import com.yty.pojo.Result;
import com.yty.service.EmpService;
import com.yty.service.StudentService;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
public class LoginController {

    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.info("登录，参数：username:{} password:{}",emp.getUsername(),emp.getPassword());
        LoginInfo loginInfo = empService.findEmpByNameAndPassword(emp);
        if (loginInfo==null) return Result.error("用户名或密码错误");
        log.info("登录，结果：{}",loginInfo);
        return Result.success(loginInfo);
    }
}
